package leetcode_day._2021._202105._0110;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/1 21:13
 * 员工的重要性
 * 算法：哈希表  深度优先搜索
 * 把列表通过遍历转化成哈希表
 * 然后再深度搜索
 */
public class _01_690 {
    class Employee {
        public int id;
        public int importance;
        public List<Integer> subordinates;
    }
    int ans = 0;
    Map<Integer, Employee> map = new HashMap<>();

    public int getImportance(List<Employee> employees, int id) {
        for (Employee employee : employees) map.put(employee.id, employee);
        dfs(id);
        return ans;
    }
    public void dfs(int id) {
        Employee employee = map.get(id);
        ans += employee.importance;
        if (employee.subordinates.size() == 0) return;
        for (Integer subordinate : employee.subordinates) dfs(subordinate);
    }
}
